package com;

import java.io.File;
import java.util.Scanner;

/**
 * @ClassName FileNameRead
 * @Description TODO
 * @Author 李伟松
 * @CreateDate 2019-06-07 下午 10:55
 * @UpdateDate 2019-06-07 下午 10:55
 * @Version 1.0
 */
public class FileNameRead {
    public static void main(String[] args) {
        FileNameRead read = new FileNameRead();
        File file=read.judge();
        read.putDigui(0,file);
    }


    public File judge() {
        Scanner in = new Scanner(System.in);
        File file = null;
        String strPath = null;
        System.out.print("请输入一个文件夹路径(如F:\\a):");
        while (true) {
            strPath = in.next();
            file = new File(strPath);
            if (file.exists())
                break;
            else
                System.out.println("文件夹不存在，重新输入(如F:\\a):");
        }
        return file;
    }


    public void putLev(int lev) {
        for(int i=0;i<lev;i++) {
            System.out.print("——>");
        }
    }

    public void putDigui(int lev,File file) {
        putLev(lev);
        System.out.println(file.getName());
        lev++;
        if (file.isDirectory()) {
            File[] fi=file.listFiles();
            for(File f:fi) {
                putDigui(lev,f);
            }
        }
    }

}
